package com.iexbuy.ihg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.common.CommUtil;
import com.iexbuy.ihg.entity.DealHistoryDetailObject;
import com.iexbuy.ihg.utils.StringUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

;

public class DealHistoryDetailListAdapter extends BaseAdapter {

	private List<DealHistoryDetailObject> datas = new ArrayList<DealHistoryDetailObject>();
	private Context context;

	public DealHistoryDetailListAdapter(Context context, List<DealHistoryDetailObject> datas) {
		super();
		this.context = context;
		if (datas != null) this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int location) {
		return datas.get(location);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.fragment_wede_order_list_item, null);
		}
		DealHistoryDetailObject vo = (DealHistoryDetailObject)datas.get(position);
		convertView.setTag(vo);



		String payInfo = "金币" + new BigDecimal(StringUtil.checkNull(vo.getPayCoin(), "0")).setScale(0, BigDecimal.ROUND_DOWN) + "个";
		if ("2".equalsIgnoreCase(vo.getPayType())) {
			payInfo = "现金" + new BigDecimal(StringUtil.checkNull(vo.getPayMoney(), "0")).setScale(2,BigDecimal.ROUND_DOWN) + "元";
		}
		((TextView) convertView.findViewById(R.id.itemName)).setText(vo.getName());
		((TextView) convertView.findViewById(R.id.itemTime)).setText(vo.getTime());
		((TextView) convertView.findViewById(R.id.itemStatus)).setText(CommUtil.getStatusNameFromCode(vo.getStatus()));
		((TextView) convertView.findViewById(R.id.itemPayAmount)).setText(payInfo);
		App.bitmapUtils.display((ImageView) convertView.findViewById(R.id.itemImage), vo.getThumbnailUrl());

		return convertView;
	}
	
	private Double getMagnitude(String magnitudeStr) {
		Double magnitude = Double.valueOf("0");
		try {
			magnitude = Double.valueOf(magnitudeStr);
		} catch (Exception e) {
		}
		return magnitude;
	}
	
}
